/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sessionbean;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import supportlearning.entities.Subject;

/**
 *
 * @author Huy
 */
@Stateless
public class SubjectFacade extends AbstractFacade<Subject> implements SubjectFacadeLocal {

    @PersistenceContext(unitName = "EprojectCMSSupportLearning-ejbPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public SubjectFacade() {
        super(Subject.class);
    }

    public List<Subject> listsub(int semid) {
        List<Subject> listsubbysem = null;
        Query q = em.createQuery("SELECT s FROM Subject s WHERE s.semester.semesterId = :semid");
        q.setParameter("semid", semid);
        return listsubbysem = q.getResultList();
        
    }

    public Subject findSubByID(int id) {
        return em.find(Subject.class, id);
    }
}
